package com.itheima.info.manager.system.dao;

import com.itheima.info.manager.system.domain.Student;

public class StudentDao {
    private static Student[] stus=new Student[40];
//查看学生
    public  Student[] findAllStudent() {
        return stus;
    }


    //添加学生
    public boolean addStudent(Student student){
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if (stu==null){
                stus[i] =student;
                return true;
            }
        }
        return false;
    }
//根据学号找索引
    public int getIndex(String sid){
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if(stu != null && stu.getSid().equals(sid)){
                return i;
            }
        }
        return -1;
    }
    public void deleteStudent(String sid){
        int index = getIndex(sid);
        stus[index]=null;
    }
    public void updateStudent(String sid,Student student){
        int index = getIndex(sid);
        stus[index]=student;
    }
}
